Skip to content

HTTPCLIENT-1165: Add optional request collapsing for async cache misses#781

Open
arturobernalg wants to merge 2 commits into
apache:masterfrom
arturobernalg:HTTPCLIENT-1165-1
Open

HTTPCLIENT-1165: Add optional request collapsing for async cache misses#781
arturobernalg wants to merge 2 commits into
apache:masterfrom
arturobernalg:HTTPCLIENT-1165-1

Conversation

@arturobernalg
Copy link
Copy Markdown
Member

This change adds an optional request collapsing mechanism to the async caching executor to prevent multiple concurrent requests from fetching the same cacheable resource on a cold miss. When enabled, a single leader request is allowed to proceed to the backend while followers wait and then re-check the cache once the leader completes. The feature is disabled by default and is covered by unit tests for the collapser and an integration-style test validating that backend requests are reduced to one under concurrency.

@arturobernalg arturobernalg requested a review from ok2c January 11, 2026 17:58
@ok2c
Copy link
Copy Markdown
Member

ok2c commented Apr 4, 2026

@arturobernalg There is a lot of complexity in this change-set for what I personally see is little practical gain.

Question. How well is this tested? How sure you are this is going to work reliably?

@arturobernalg
Copy link
Copy Markdown
Member Author

@arturobernalg There is a lot of complexity in this change-set for what I personally see is little practical gain.

Question. How well is this tested? How sure you are this is going to work reliably?

@ok2c
I added additional coverage for the unsafe paths: leader failure, leader cancellation, non-cacheable responses, Vary, request entities and only-if-cached. I also kept request collapsing disabled by default and scoped to each caching executor.
The local smoke example produces 20 origin requests without collapsing and 1 with collapsing enabled for concurrent cold misses.

@arturobernalg arturobernalg requested a review from ok2c May 24, 2026 11:28
Coalesce concurrent cacheable async requests for the same cache key so that
only one backend request is executed on a cold miss. Waiting requests re-check
the cache after the leader completes.
Request collapsing is disabled by default and scoped to each caching executor.
/**
* Demonstrates optional request collapsing for concurrent async cache misses.
*/
public class AsyncClientCacheRequestCollapsing {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturobernalg Your examples tend to look like integration tests. This is not the point of examples. They need to demonstrate the use of APIs abd be informative. Please drop the server side code and just focus on the client APIs.

@arturobernalg arturobernalg requested a review from ok2c May 24, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants